#include "CSetAnimationCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetAnimationCommand::CSetAnimationCommand (int id, stringc name, int newValue)
{
	m_id = id;
	m_name = name;
	m_oldValue = editor->getSceneObjectFromID(id)->m_UserData->getAttributeAsInt(name.c_str());
	m_newValue = newValue;
	setDescription(stringw(L"change ") + name.c_str());
}

void CSetAnimationCommand::redo ()
{
	CSceneObject* obj = editor->getSceneObjectFromID(m_id);
	obj->m_UserData->setAttribute(m_name.c_str(), m_newValue);
	((IAnimatedMeshSceneNode*)obj->m_SceneNode)->setFrameLoop(obj->m_Animations[m_newValue].startFrame, obj->m_Animations[m_newValue].endFrame);
}

void CSetAnimationCommand::undo ()
{
	CSceneObject* obj = editor->getSceneObjectFromID(m_id);
	obj->m_UserData->setAttribute(m_name.c_str(), m_oldValue);
	((IAnimatedMeshSceneNode*)obj->m_SceneNode)->setFrameLoop(obj->m_Animations[m_oldValue].startFrame, obj->m_Animations[m_oldValue].endFrame);
}
